package sys

import (
	"context"
	"video-api/utility"

	"github.com/gogf/gf/util/gmode"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/os/glog"
)

func Init(ctx context.Context) {
	setMode(ctx)
	//设置日志处理
	glog.SetDefaultHandler(LogServerHandle)
}

func setMode(ctx context.Context) {
	mode := g.Cfg().MustGet(ctx, "system.mode").String()
	if len(mode) == 0 {
		mode = gmode.NOT_SET
	}
	var modes = []string{
		gmode.DEVELOP, gmode.TESTING, gmode.STAGING, gmode.PRODUCT,
	}
	if utility.InSlice(modes, mode) {
		gmode.Set(mode)
	}
}

// LogServerHandle 日志组件
func LogServerHandle(ctx context.Context, in *glog.HandlerInput) {
	in.Next(ctx)
	//TODO 后续如果需要对日志做处理,例如日志收集
}
